package cy.action;

import java.io.IOException;
import java.util.Map;

import org.apache.struts2.ServletActionContext;
import org.apache.struts2.convention.annotation.Namespace;
import org.apache.struts2.convention.annotation.ParentPackage;
import org.apache.struts2.interceptor.ApplicationAware;
import org.apache.struts2.interceptor.RequestAware;
import org.apache.struts2.interceptor.SessionAware;

import com.alibaba.fastjson.JSON;

@ParentPackage("basePackage")
@Namespace("/")
public class BaseAction implements SessionAware, RequestAware, ApplicationAware{
	
	protected Map<String, Object> session;
	protected Map<String, Object> request;
	protected Map<String, Object> application;

	public void setApplication(Map<String, Object> arg0) {
		application = arg0;
	}

	public void setRequest(Map<String, Object> arg0) {
		request = arg0;
	}

	public void setSession(Map<String, Object> arg0) {
		session = arg0;
	}
	public void writeJson(Object obj){
		try {
			String json=JSON.toJSONStringWithDateFormat(obj,"yyyy-MM-dd HH:mm:ss");
			ServletActionContext.getResponse().setContentType("text/html;charset=utf-8");
			ServletActionContext.getResponse().getWriter().write(json);
			ServletActionContext.getResponse().getWriter().flush();
			ServletActionContext.getResponse().getWriter().close();
		} catch (IOException e) {
			e.printStackTrace();
		}
	}
	
	
}
